package cn.gson.fengboot.model.service;

import cn.gson.fengboot.model.dao.*;
import cn.gson.fengboot.model.mapper.DbusinessMapper;
import cn.gson.fengboot.model.mapper.DphaseMapper;
import cn.gson.fengboot.model.mapper.ZshipmentsMapper;
import cn.gson.fengboot.model.pojos.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
@Transactional(rollbackFor = Exception.class)
public class ZshipmentsService {

    @Autowired
    ZshipmentsDao dao;
    @Autowired
    ZshipmentsdetailsDao xqdao;
    @Autowired
    ZchukuDao ckdao;
    @Autowired
    ZdeliveryDao jfdao;
    @Autowired
    ZshipmentsMapper mapper;
    public void add(Zshipments fh){
        Zshipments save = dao.save(fh);

        fh.getXq().forEach(a->{
            a.setShipmentsId(save);
        });
        xqdao.saveAll(fh.getXq());

        Zchuku zchuku = ckdao.findById(fh.getChukuId().getChukuId()).get();
        zchuku.setChukuFahuo("已发货");
        Zdelivery zdelivery = jfdao.findById(fh.getChukuId().getDeliveryId().getDeliveryId()).get();
        zdelivery.setDeliveryStatic("已发货");
        jfdao.save(zdelivery);
        ckdao.save(zchuku);
    }

    public List<Zshipments> fahuoList(String search,String search2){
       return mapper.fahuoList(search,search2);
    }
}
